<?php 
	require_once('./template/header.tpl.php');

	include('./src/connect.php');
	include('./src/config.php');
	$keyword = $_GET['keyword'];
	if ($keyword == '') {
		header("Location: index.php");
	}
	session_start();
	$_SESSION['keyword'] = $keyword;
	$username = $_SESSION['username']; 
	
	$query = "SELECT * FROM ark_courseperiod cp LEFT OUTER JOIN ark_course c ON cp.cid=c.id WHERE cp.teacher LIKE '%$keyword%' OR c.name LIKE '%$keyword%' ORDER BY weekday,period_from";
	if ($result = mysql_query($query, $link)) {
		while ($res = mysql_fetch_array($result)) {
			print "<div id='box'><ul>"
				."<li>课程号：".$res['cid']."</li>"
				."<li>课序号：".$res['serial']."</li>"
				."<li>".$res['name']."</li>"
				."<li>".$res['teacher']."</li>"
				."<li>".$weekday[$res['weekday']]."</li>"
				."<li>".$res['period_from']."  <<->>  ".$res['period_to']."</li>";
				if ($username != '') {
					print "<li><a href='add_class.php?coursename={$res['name']}&teacher={$res['teacher']}&campus={$res['campus']}&building={$res['building']}&room={$res['room']}&weekday={$res['weekday']}&dayfrom={$res['period_from']}&dayto={$res['period_to']}'>添加课程</a></li>";	
				}
				
			print "</ul></div>";
		}
	}
	else {
		exit("No matched data");
	}

	require_once('./template/footer.tpl.php');
?>